import { find, Sprite, SpriteFrame } from 'cc';
import { view } from 'cc';
import { UITransform } from 'cc';
import { _decorator, Component, Label, Node } from 'cc';
import { App } from '../../../App';
import AbstractComponent from '../../../base/AbstractComponent';
import { EventConst } from '../../../common/Common';
import { showLuckyBallRule, showTipBox } from '../../../tools/PopuUp';
import UtilTool from '../../../tools/UtilTool';
import { ACTION_POINT_R } from '../GameManage';
import { GameModel } from '../model/GameModel';
import { GameLayer1 } from './GameLayer1';
const { ccclass, property } = _decorator;

// 结算界面
@ccclass('EndLayer1')
export class EndLayer1 extends Component {
    @property(Node)
    successNode : Node = null

    @property(Node)
    failNode : Node = null


    private viewState = null
    private parentObj = null

    start() {
        this.node.getComponent(UITransform).setContentSize(view.getVisibleSize())
    }

    /** 展示界面
     * @param state [1]胜利界面 [2]失败界面
     */
    showView(parentObj, state) {
        this.parentObj = parentObj
        this.viewState = state
        UtilTool.nodeActive(state==1?this.successNode:this.failNode,5,0.16)

        this.successNode.active = state==1
        this.failNode.active = state==2

        if (state==1) {
            App.Audio.playOneShot("game/win")
            if (App.Model.gameModel.model1_data) {
                let gameLayer = parentObj.getGameLayerCtrl(GameLayer1)
                let coinLabel = find("coinLabel",this.successNode).getComponent(Label)
                coinLabel.string = App.language.getLanguageLab(50) + gameLayer.baseCoin + "x" + App.Model.gameModel.model1_data.hitOdds + App.language.getLanguageLab(51)
            }
            
        }
        else if (state==2) {
            App.Audio.playOneShot("game/fail")
        }
        else {
            this.node.destroy()
        }
    }

    /** 
     * 再次挑战
      */
    clickAgain() {
        App.Audio.playOneShot("click")
        App.Model.gameView.backToHall()
    }

    /** 
     * 确定
      */
    clickSure() {
        App.Audio.playOneShot("click")
        App.Model.gameView.backToHall()
    }

    onDestroy() {
        
    }
}

